/****************************************************
          File Name:msgrcv.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Thu 11 Sep 2014 10:36:25 AM CST
*****************************************************/

#include"msg.h"

int main(int argc,char *argv[])
{
    int status;
    struct msgbuf msgp;

    if(argc<3)
    {
        printf("%s msgid mtype\n",argv[0]);
        exit(1);
    }

    msgp.mtype=atoi(argv[2]);

    status=msgrcv(atoi(argv[1]),&msgp,DATA_SIZE,0,IPC_NOWAIT);
    if(status==-1)
        err("msgrcv");

    printf("the message is:\n%s\n",msgp.mtext);
    return 0;
}
